/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package pl.lodz.p.ftims.ProjektZespolowy2.entities;

import java.io.Serializable;
import java.util.Collection;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author Łukasz Gadomski
 */
@Entity
@Table(name = "objects")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Objects.findAll", query = "SELECT o FROM Objects o"),
    @NamedQuery(name = "Objects.findByObjectId", query = "SELECT o FROM Objects o WHERE o.objectId = :objectId"),
    @NamedQuery(name = "Objects.findByName", query = "SELECT o FROM Objects o WHERE o.name = :name"),
    @NamedQuery(name = "Objects.findByAdress", query = "SELECT o FROM Objects o WHERE o.adress = :adress"),
    @NamedQuery(name = "Objects.findByPostCode", query = "SELECT o FROM Objects o WHERE o.postCode = :postCode")})
public class Objects implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "object_id")
    private Integer objectId;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 100)
    @Column(name = "name")
    private String name;
    @Size(max = 255)
    @Column(name = "adress")
    private String adress;
    @Size(max = 6)
    @Column(name = "post_code")
    private String postCode;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "hospitalId")
    private Collection<Appointment> appointmentsCollection;
    @JoinColumn(name = "ward_id", referencedColumnName = "ward_id")
    @ManyToOne(optional = false)
    private Ward wardId;
    @JoinColumn(name = "city_id", referencedColumnName = "city_id")
    @ManyToOne
    private City cityId;
    @JoinColumn(name = "object_type_id", referencedColumnName = "object_type_id")
    @ManyToOne(optional = false)
    private ObjectType objectTypeId;

    public Objects() {
    }

    public Objects(Integer objectId) {
        this.objectId = objectId;
    }

    public Objects(Integer objectId, String name) {
        this.objectId = objectId;
        this.name = name;
    }

    public Integer getObjectId() {
        return objectId;
    }

    public void setObjectId(Integer objectId) {
        this.objectId = objectId;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getAdress() {
        return adress;
    }

    public void setAdress(String adress) {
        this.adress = adress;
    }

    public String getPostCode() {
        return postCode;
    }

    public void setPostCode(String postCode) {
        this.postCode = postCode;
    }

    @XmlTransient
    public Collection<Appointment> getAppointmentsCollection() {
        return appointmentsCollection;
    }

    public void setAppointmentsCollection(Collection<Appointment> appointmentsCollection) {
        this.appointmentsCollection = appointmentsCollection;
    }

    public Ward getWardId() {
        return wardId;
    }

    public void setWardId(Ward wardId) {
        this.wardId = wardId;
    }

    public City getCityId() {
        return cityId;
    }

    public void setCityId(City cityId) {
        this.cityId = cityId;
    }

    public ObjectType getObjectTypeId() {
        return objectTypeId;
    }

    public void setObjectTypeId(ObjectType objectTypeId) {
        this.objectTypeId = objectTypeId;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (objectId != null ? objectId.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Objects)) {
            return false;
        }
        Objects other = (Objects) object;
        if ((this.objectId == null && other.objectId != null) || (this.objectId != null && !this.objectId.equals(other.objectId))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "pl.lodz.p.ftims.ProjektZespolowy2.entities.Objects[ objectId=" + objectId + " ]";
    }
    
}
